//
//  FMView.m
//  DolphinMusic
//
//  Created by dllo on 15/3/27.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "FMView.h"

@implementation FMView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)dealloc
{
    [_view1 release];
    [_coverImageView release];
    [_titleLabel release];
    [_playImageView release];
    [_playLabel release];
    [_sourceCountImageVIew release];
    [_sourceCountLabel release];
    [_album release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        CGFloat width = frame.size.width;
        CGFloat height = frame.size.height;
        
        self.coverImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 0, height - 10, height - 10)];
        self.coverImageView.userInteractionEnabled = YES;
        [self addSubview:self.coverImageView];
        self.coverImageView.layer.cornerRadius = 10;
        self.coverImageView.clipsToBounds = YES;
        [_coverImageView release];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(height + 2, 0, width - height - 2, height / 2)];
        
        [self addSubview:self.titleLabel];
        
        self.playImageView = [[UIImageView alloc] initWithFrame:CGRectMake(height + 2, height / 2 , height / 3, height / 3)];
        
        [self addSubview:self.playImageView];
        [_playLabel release];
        
        self.playLabel = [[UILabel alloc] initWithFrame:CGRectMake(height + 2 + height / 3 + 2, height / 2 - 3, 65, height / 2)];
        
        [self addSubview:self.playLabel];
        [_playLabel release];
        
        self.sourceCountImageVIew = [[UIImageView alloc] initWithFrame:CGRectMake(self.playLabel.frame.origin.x + self.playLabel.frame.size.width + 2, height / 2, height / 3, height / 3)];
        [self addSubview:self.sourceCountImageVIew];
        [_sourceCountImageVIew release];
        
        self.sourceCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.sourceCountImageVIew.frame.origin.x + self.sourceCountImageVIew.frame.size.width + 1, height / 2 - 3, width - (self.sourceCountImageVIew.frame.origin.x + self.sourceCountImageVIew.frame.size.width + 1), height / 2)];
        
        [self addSubview:self.sourceCountLabel];
        [_sourceCountLabel release];
        
        self.view1 = [[UIView alloc] initWithFrame:CGRectMake(5, 5, width - 10, height - 10)];
        self.view1.backgroundColor = [UIColor clearColor];
        [self addSubview:self.view1];
        [_view1 release];
        
    }
    return self;
}

- (void)setAlbum:(FMAlbum *)album
{
    if (_album != album) {
        [_album release];
        _album = [album retain];
    }
    [self.coverImageView setImageWithURL:[NSURL URLWithString:[self.album.albumCoverUrl290 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
    
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    self.titleLabel.text = self.album.title;
    
    self.playImageView.image = [UIImage imageNamed:@"playNumber.png"];

    self.playImageView.alpha = 0.7;
    
    self.playLabel.font = [UIFont systemFontOfSize:14];
    self.playLabel.text = self.album.playCounts;
    
    self.sourceCountImageVIew.image = [UIImage imageNamed:@"sourceNumber.png"];

    self.sourceCountImageVIew.alpha = 0.7;

    self.sourceCountLabel.text = self.album.trackCounts;
    self.sourceCountLabel.font = [UIFont systemFontOfSize:14];
    
}



@end
